package com.example.utils;

import java.io.File;
import java.util.Date;
import java.util.Random;

/**
 * 参数调整解析控制工具类
 */
public class DealNumber {
    /**
     * 判断参数是否为空，为空返回”“，非空返回原字符串
     *
     * @param str
     * @return
     */
    public static String nullToString(String str) {
        String result;
        if (str == null) {
            result = "";
        } else {
            result = str;
        }
        return result;
    }

    public static String randomCode() {
        StringBuilder str = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i < 6; i++) {
            str.append(random.nextInt(10));
        }
        return str.toString();
    }

    public static String imgcode() {
        long time = new Date().getTime();
        String timestr = String.valueOf(time);
        return timestr;
    }


    public static void deltxt(String path) {
        File f = new File(path); // 输入要删除的文件位置
        if (f.exists())
            f.delete();
    }
}
